#include "faceobject.h"
#include <QDebug>

FaceObject::FaceObject(QObject *parent) : QObject(parent)
{
    //初始化
    seeta::ModelSetting FDmode("C:/Qt+opencv/SeetaFace/bin/model/fd_2_00.dat",seeta::ModelSetting::CPU,0);
    seeta::ModelSetting PDmode("C:/Qt+opencv/SeetaFace/bin/model/pd_2_00_pts5.dat",seeta::ModelSetting::CPU,0);
    seeta::ModelSetting FRmode("C:/Qt+opencv/SeetaFace/bin/model/fr_2_10.dat",seeta::ModelSetting::CPU,0);
    this->fengineptr = new seeta::FaceEngine(FDmode,PDmode,FRmode);

    //导入已有人脸数据库
    this->fengineptr->Load("./face.db");
}

FaceObject::~FaceObject()
{
    delete fengineptr;
}

//人脸注册
int FaceObject::face_register(Mat &faceimage)
{
    //把opencv的Mat数据转为seetface的数据
    SeetaImageData simage;
    simage.data = faceimage.data;
    simage.width = faceimage.cols;
    simage.height = faceimage.rows;
    simage.channels = faceimage.channels();
    int faceid = this->fengineptr->Register(simage);  //注册返回一个人脸id
    if(faceid >= 0)
    {
        fengineptr->Save("./face.db");
    }
    return faceid;
}

//人脸查询
int FaceObject::face_query(Mat &faceimage)
{
    //把opencv的Mat数据转为seetface的数据
    SeetaImageData simage;
    simage.data = faceimage.data;
    simage.width = faceimage.cols;
    simage.height = faceimage.rows;
    simage.channels = faceimage.channels();
    float similary = 0;
    int faceid = this->fengineptr->Query(simage,&similary);  //查询
    qDebug()<<"查询"<<faceid<<similary;
    if(similary > 0.7)
    {
        emit send_faceid(faceid);
    }
    else
    {
        emit send_faceid(-1);
    }

    return faceid;
}
